 //
//  IntegralViewController.m
//  Light
//
//  Created by 骁唐 on 15/8/27.
//  Copyright (c) 2015年 骁唐. All rights reserved.
//

#import "IntegralViewController.h"
#import "AFNetworking.h"
#import "NetworkTool.h"
#import "constantDefinition.h"
#import "UserConfig.h"
#import "UIImageView+WebCache.h"
#import "FirstRangeTableViewCell.h"
#import "SecondRangeTableViewCell.h"
#import "UMSocial.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
@interface IntegralViewController ()<MBProgressHUDDelegate,UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *OneView;
@property (weak, nonatomic) IBOutlet UIView *TwoView;
@property (weak, nonatomic) IBOutlet UIImageView *backGround;
@property (weak, nonatomic) IBOutlet UITableView *SleepTableView;
//经验条 experienceLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *experienceLayout;
//绿色条
@property (weak, nonatomic) IBOutlet UIImageView *experienceView;
//进度条view需要切圆
@property (weak, nonatomic) IBOutlet UIView * viewExperience;

//分数数组
@property (strong,nonatomic) NSMutableArray *totalpointsAry;
//时长数组
@property (strong,nonatomic) NSMutableArray *reporttimeAry;
//显示的Judge
@property (assign,nonatomic) BOOL judgeScoreOrTime;
//按钮图片
@property (weak, nonatomic) IBOutlet UIImageView *sleepScore;
@property (weak, nonatomic) IBOutlet UIImageView *sleeptime;
//按钮点击
@property (weak, nonatomic) IBOutlet UIButton *sleepTimeBtn;
@property (weak, nonatomic) IBOutlet UIButton *sleepScoreBtn;
//分数排行  如:  189/300
@property (weak,nonatomic) IBOutlet UILabel * labelScroe;

@end


@implementation IntegralViewController
{
    UIAlertView *alert;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //强制竖屏
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    self.TwoView.alpha = 0.0f;
    [self judgeBackGroundTime];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self gesture];
    
    _levelLabel.text = @"Lv1";
    
    MBProgressHUD *progressView = [[MBProgressHUD alloc]initWithView:self.view];
    progressView.delegate       = self;
    progressView.labelText      = @"";
    self.mbProgressHud       = progressView;
    [self.view addSubview:progressView];

    [_userHeadImage.layer setMasksToBounds:YES];
    [_userHeadImage.layer setCornerRadius:45.0f];
    
    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
    self.todayScore.text = [[NSString alloc] initWithFormat:@"%d",delegate.sleepScore];
    
    self.totalpointsAry = [[NSMutableArray alloc] init];
    self.reporttimeAry  = [[NSMutableArray alloc] init];
    
    [self getUserInfo];
}


//加手势
- (void)gesture
{
    UISwipeGestureRecognizer  *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    UISwipeGestureRecognizer *recognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizerRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [self.view addGestureRecognizer:recognizerRight];
    [self.view addGestureRecognizer:recognizer];

}
//手势监听
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
    if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
        
    [UIView animateWithDuration:0.5 animations:^{
        self.OneView.alpha = 0.f;
        self.TwoView.alpha = 1.0f;
    }];
        [self getPKInfo];
    }
    else if (recognizer.direction==UISwipeGestureRecognizerDirectionRight){
            [UIView animateWithDuration:0.5 animations:^{
                self.OneView.alpha = 1.f;
                self.TwoView.alpha = 0.0f;
            }];
    }
}
#pragma mark  UITableViewDataSource,UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (self.judgeScoreOrTime) {
        
        return self.reporttimeAry.count;
    }else
    {
        return self.totalpointsAry.count;
       
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 100;
    }else {
        return 60;
    }
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *firstCellId = @"firstCell";
    static NSString *secondCellId = @"otherCell";
    if (self.judgeScoreOrTime == NO) {
        if (indexPath.row == 0) {
            FirstRangeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:firstCellId];
            cell.firstNameLabel.text = self.totalpointsAry[indexPath.row][@"Name"];
            cell.firstLevelLabel.text = @"1";
            cell.firstScoreLabel.text = self.totalpointsAry[indexPath.row][@"todaypoint"];
           // cell.firstHeadImage.image = self.totalpointsAry[indexPath.row][@"headPortrait"];
            [cell.firstHeadImage sd_setImageWithURL:[NSURL URLWithString:self.totalpointsAry[indexPath.row][@"headPortrait"]] placeholderImage:nil];
            return cell;
        }else {
            SecondRangeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:secondCellId];
            cell.secondLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row + 1];
          //  cell.secondHeadImage.image = self.totalpointsAry[indexPath.row][@"headPortrait"];
            [cell.secondHeadImage sd_setImageWithURL:[NSURL URLWithString:self.totalpointsAry[indexPath.row][@"headPortrait"]] placeholderImage:nil];
            cell.secondNameLabel.text = self.totalpointsAry[indexPath.row][@"Name"];
            return cell;
    }
        
    }else
    {
        if (indexPath.row == 0) {
            FirstRangeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:firstCellId];
            cell.firstNameLabel.text = self.reporttimeAry[indexPath.row][@"Name"];
            cell.firstLevelLabel.text = @"1";
            cell.firstScoreLabel.text = self.reporttimeAry[indexPath.row][@"todaypoint"];
            // cell.firstHeadImage.image = self.totalpointsAry[indexPath.row][@"headPortrait"];
            [cell.firstHeadImage sd_setImageWithURL:[NSURL URLWithString:self.reporttimeAry[indexPath.row][@"headPortrait"]] placeholderImage:nil];
            return cell;
        }else {
            SecondRangeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:secondCellId];
           cell.secondLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row + 1];
            //  cell.secondHeadImage.image = self.totalpointsAry[indexPath.row][@"headPortrait"];
            [cell.secondHeadImage sd_setImageWithURL:[NSURL URLWithString:self.reporttimeAry[indexPath.row][@"headPortrait"]] placeholderImage:nil];
            cell.secondNameLabel.text = self.reporttimeAry[indexPath.row][@"Name"];
            return cell;
        }
        
    }
    
    return nil;
}

#pragma mark 获取用户信息
- (void)getUserInfo {
    
    [_mbProgressHud show:YES];
    
    UserConfig *userConfig = [UserConfig sharingUserConfig];
    
    AFHTTPRequestOperationManager *httpManager = [AFHTTPRequestOperationManager manager];
    httpManager.requestSerializer = [[AFHTTPRequestSerializer alloc]init];
    httpManager.responseSerializer = [[AFHTTPResponseSerializer alloc]init];
    
    
    NSDictionary *dic = @{@"Token":[userConfig getToken]};
    //地址
    [httpManager POST:GET_INFO parameters:dic
              success:^(AFHTTPRequestOperation *operation, id responseObject) {
                  
                  NSDictionary *dic = [NetworkTool toNSDictionary:responseObject];
                  NSLog(@"获取成功");
                  
                  NSDictionary *resDic = [NetworkTool parseJSONStringToNSDictionary:dic[@"b"]];
                  
                  if ([dic[@"a"] intValue] == 1) {
                      [_userHeadImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",PICTURE_HEAD,resDic[@"image"]]] placeholderImage:[UIImage imageNamed:@"user - head"]];
                      //_worldNumLabel.text = dic[@"c"];
//                      _levelLabel.text = [NSString stringWithFormat:@"Lv%@",resDic[@"grade"]];
                      _totalScore.text = [NSString stringWithFormat:@"%@分",resDic[@"totalpoints"]];
                      NSString *Score = resDic[@"totalpoints"];
                      
                      if ([_totalScore.text intValue] <=300) {
                          _levelLabel.text = @"Lv1";
                          int needScore = 300 - [resDic[@"totalpoints"] intValue];
                          _needScoreLabel.text = [[NSString alloc] initWithFormat:@"%d",needScore];
                          _nextNickName.text = @"万睡爷";
                          self.labelScroe.text = [NSString stringWithFormat:@"%@/300",resDic[@"totalpoints"]];
                          //进度条
                          if ([_totalScore.text intValue] == 0)
                          {
                              self.experienceView.hidden = YES;//隐藏进度条
                          }else
                          {
                              self.experienceLayout.constant = (float)(((float)[Score intValue]/300.0)*280);
                              self.experienceView.layer.cornerRadius = 20;
                              self.experienceView.layer.masksToBounds = YES;
                              self.viewExperience.layer.cornerRadius = 20;
                              self.viewExperience.layer.masksToBounds = YES;
                              [self.view layoutIfNeeded];
                          }
                         
                          if ([[userConfig getCurrentUserGender] isEqualToString:@"男"]) {
                            _nickName.text = @"睡美男";
                          }else if ([[userConfig getCurrentUserGender] isEqualToString:@"女"])
                          {
                                _nickName.text = @"睡美人";
                          }else
                          {
                                _nickName.text = @"睡美人";
                          }
                      }else if ([_totalScore.text intValue] >300 && [_totalScore.text intValue] <= 800)
                      {
                          self.experienceView.hidden = NO;
                          int needScore = 800 - [_totalScore.text intValue];
                          self.labelScroe.text = [NSString stringWithFormat:@"%@/800",resDic[@"totalpoints"]];
                          _needScoreLabel.text = [[NSString alloc] initWithFormat:@"%d",needScore];
                          _nextNickName.text = @"觉兽";
                          _levelLabel.text = @"Lv2";
                          _nickName.text = @"万睡爷";
                          //进度条
                          self.experienceLayout.constant =(float)(((float)[Score intValue]/800.0)*280);
                          self.experienceView.layer.cornerRadius = 20;
                          self.experienceView.layer.masksToBounds = YES;
                          self.viewExperience.layer.cornerRadius = 20;
                          self.viewExperience.layer.masksToBounds = YES;
                          [self.view layoutIfNeeded];
                          
                      }else if ([_totalScore.text intValue] >800 && [_totalScore.text intValue] <= 1500)
                      {
                            self.experienceView.hidden = NO;
                          int needScore = 1500 - [_totalScore.text intValue];
                          self.labelScroe.text = [NSString stringWithFormat:@"%@/1500",resDic[@"totalpoints"]];

                          _needScoreLabel.text = [[NSString alloc] initWithFormat:@"%d",needScore];
                          _nextNickName.text = @"觉主";
                          _levelLabel.text = @"Lv3";
                          _nickName.text = @"觉兽";
                          //进度条
                          self.experienceLayout.constant = (float)(((float)[Score intValue]/1500.0)*280);
                          self.experienceView.layer.cornerRadius = 20;
                          self.experienceView.layer.masksToBounds = YES;
                          self.viewExperience.layer.cornerRadius = 20;
                          self.viewExperience.layer.masksToBounds = YES;
                          [self.view layoutIfNeeded];
                          
                      }else if ([_totalScore.text intValue] >1500 && [_totalScore.text intValue] <= 3000)
                      {
                            self.experienceView.hidden = NO;
                          int needScore = 3000 - [_totalScore.text intValue];
                          _needScoreLabel.text = [[NSString alloc] initWithFormat:@"%d",needScore];
                          _nextNickName.text = @"觉皇";
                          _levelLabel.text = @"Lv4";
                          _nickName.text = @"觉主";
                          self.labelScroe.text = [NSString stringWithFormat:@"%@/3000",resDic[@"totalpoints"]];

                          
                          //进度条
                          self.experienceLayout.constant = (float)(((float)[Score intValue]/3000.0)*280);
                          self.experienceView.layer.cornerRadius = 20;
                          self.experienceView.layer.masksToBounds = YES;
                          self.viewExperience.layer.cornerRadius = 20;
                          self.viewExperience.layer.masksToBounds = YES;
                          [self.view layoutIfNeeded];
                          
                      }else if ([_totalScore.text intValue] >3000 && [_totalScore.text intValue] <= 5000)
                      {
                            self.experienceView.hidden = NO;
                          int needScore = 5000 - [_totalScore.text intValue];
                          _needScoreLabel.text = [[NSString alloc] initWithFormat:@"%d",needScore];
                          _nextNickName.text = @"睡眠宝宝";
                          _levelLabel.text = @"Lv5";
                          _nickName.text = @"觉皇";
                          self.labelScroe.text = [NSString stringWithFormat:@"%@/5000",resDic[@"totalpoints"]];

                          //进度条
                          self.experienceLayout.constant = (float)(((float)[Score intValue]/5000.0)*280);;
                          self.experienceView.layer.cornerRadius = 20;
                          self.experienceView.layer.masksToBounds = YES;
                          self.viewExperience.layer.cornerRadius = 20;
                          self.viewExperience.layer.masksToBounds = YES;
                          [self.view layoutIfNeeded];
                          
                      }
                      else if ([_totalScore.text intValue] >5000)
                      {
                            self.experienceView.hidden = NO;
                          _needScoreLabel.text = @"0";
                          _nextNickName.text = @"睡眠宝宝";
                          _levelLabel.text = @"Lv6";
                          _nickName.text = @"睡眠宝宝";
                          //进度条
                          self.experienceLayout.constant = 300;
                          self.labelScroe.text = resDic[@"totalpoints"];//设置分数就行
                          self.viewExperience.layer.cornerRadius = 20;
                          self.viewExperience.layer.masksToBounds = YES;
                          [self.view layoutIfNeeded];

                      }
                  }else if ([dic[@"a"] intValue] == -1) {
                      if (TJJiOS8)
                      {
                          UIAlertController  * Alertview =  [UIAlertController alertControllerWithTitle:@"您的登录过期,请您重新登录" message:nil preferredStyle:UIAlertControllerStyleAlert];
                          
                          [self presentViewController:Alertview animated:YES completion:nil];
                          
                          UIAlertAction *action = [UIAlertAction actionWithTitle:@"重新登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                              
                              UserConfig *config = [UserConfig sharingUserConfig];
                              [config setHaveLogin:@"lalala"];
                              [config setToken:@"123"];
                              [config setUserHeadData:nil];
                              
                              UIStoryboard *LoginSt = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
                              LoginViewController *loginVc = [LoginSt instantiateViewControllerWithIdentifier:@"loginViewId"];
                              loginVc.quit = YES;
                              [self.navigationController pushViewController:loginVc animated:YES];
                          }];
                          
                          [Alertview addAction:action];
                      }
                      else
                      {
                          UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的登录过期,请您重新登录" delegate:self cancelButtonTitle:@"重新登录" otherButtonTitles:nil, nil];
                          alertView.tag = 97;
                          [alertView show];
                      }
                  }else if ([dic[@"a"] intValue] == 0) {
                      ALERT_VIEW(@"获取失败");
                  }
                  _mbProgressHud.hidden = YES;
                  
              }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                  ALERT_VIEW(@"信息获取失败");
                  _mbProgressHud.hidden = YES;
              }];
}

#pragma mark  获取用户PK数据
- (void)getPKInfo {
    [_mbProgressHud setHidden: NO];
    UserConfig *userConfig = [UserConfig sharingUserConfig];
    AFHTTPRequestOperationManager *httpManager = [AFHTTPRequestOperationManager manager];
    httpManager.requestSerializer = [[AFHTTPRequestSerializer alloc]init];
    httpManager.responseSerializer = [[AFHTTPResponseSerializer alloc]init];
    NSDictionary *dic = @{@"Token":[userConfig getToken]};
    __weak IntegralViewController *weakSelf  = self;
    //地址
    [httpManager POST:HAOYOU_PK parameters:dic
              success:^(AFHTTPRequestOperation *operation, id responseObject) {
                  NSDictionary *dic = [NetworkTool toNSDictionary:responseObject];
                  NSLog(@"获取成功");
               NSMutableArray *resDic = [NetworkTool parseJSONStringToNSMutableArray:dic[@"b"]];
                  if ([dic[@"a"] intValue] == 1) {
                      NSDate *  senddate=[NSDate date];
                      NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
                      [dateformatter setDateFormat:@"YYYY-MM-dd"];
                      NSString *  locationString=[dateformatter stringFromDate:senddate];
                      NSArray *sortDesc = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"totalpoints" ascending:NO]];
                      NSArray *sortedArr = [resDic sortedArrayUsingDescriptors:sortDesc];
                        NSLog(@"排序后的数组:%@",sortedArr);
                      for (int i = 0; i < sortedArr.count; i ++) {
                          if ([sortedArr[i][@"reporttime"] isKindOfClass:[NSNull class]] || [sortedArr[i][@"starttime" ] isKindOfClass:[NSNull class]] )
                          {
                              continue;
                          }
                          else
                          {
                              NSString * currentTime = [sortedArr[i][@"starttime"] substringWithRange:NSMakeRange(0, 10)];
                              if([currentTime isEqualToString:locationString])
                              {
                              [weakSelf.totalpointsAry addObject:sortedArr[i]];
                              }
                          }
                      }
                      NSArray *myAry = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"reporttime" ascending:NO]];
                      NSArray *TimeAry = [resDic sortedArrayUsingDescriptors:myAry];
                      NSLog(@"排序后的时间数组:%@",TimeAry);
                      
                      for (int i = 0; i < TimeAry.count; i ++)
                      {
                          if ([TimeAry[i][@"reporttime"] isKindOfClass:[NSNull class]] || [TimeAry[i][@"starttime" ] isKindOfClass:[NSNull class]] ) {
                              continue;
                          }else
                          {
                            NSString * currentTime = [TimeAry[i][@"starttime"] substringWithRange:NSMakeRange(0, 10)];
                              if([currentTime isEqualToString:locationString])
                              {
                                   [weakSelf.reporttimeAry addObject:TimeAry[i]];
                              }
                          }
                      }
                      NSLog(@"----------%@ ----- %@",weakSelf.totalpointsAry,weakSelf.reporttimeAry);
                  }else if ([dic[@"a"] intValue] == -1) {
                      if (TJJiOS8)
                      {
                          UIAlertController  * Alertview =  [UIAlertController alertControllerWithTitle:@"您的登录过期,请您重新登录" message:nil preferredStyle:UIAlertControllerStyleAlert];
                          
                          [self presentViewController:Alertview animated:YES completion:nil];
                          
                          UIAlertAction *action = [UIAlertAction actionWithTitle:@"重新登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                              
                              UserConfig *config = [UserConfig sharingUserConfig];
                              [config setHaveLogin:@"lalala"];
                              [config setToken:@"123"];
                              [config setUserHeadData:nil];
                              
                              UIStoryboard *LoginSt = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
                              LoginViewController *loginVc = [LoginSt instantiateViewControllerWithIdentifier:@"loginViewId"];
                              loginVc.quit = YES;
                              [self.navigationController pushViewController:loginVc animated:YES];
                          }];
                          
                          [Alertview addAction:action];
                      }
                      else
                      {
                          UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的登录过期,请您重新登录" delegate:self cancelButtonTitle:@"重新登录" otherButtonTitles:nil, nil];
                          alertView.tag = 97;
                          [alertView show];
                      }
                  }else if ([dic[@"a"] intValue] == 0) {
                      
                      ALERT_VIEW(@"获取失败");
                  }
                  _mbProgressHud.hidden = YES;
                  
              }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                  ALERT_VIEW(@"信息获取失败");
                  _mbProgressHud.hidden = YES;
                  
              }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark -
#pragma mark 返回按钮
- (IBAction)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -
#pragma mark 分享按钮
- (IBAction)shareBtnAction:(id)sender {
    //传的参数
    UserConfig *config =[UserConfig sharingUserConfig];
    NSDictionary *dic= @{@"Token":[config getToken]};
    AFHTTPRequestOperationManager *httpManager = [AFHTTPRequestOperationManager manager];
    httpManager.requestSerializer = [[AFHTTPRequestSerializer alloc] init];
    httpManager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    //地址
    [httpManager POST:HOME_SHARE parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary *retDic = [NetworkTool toNSDictionary:responseObject];
        NSDictionary *Dic = [NetworkTool parseJSONStringToNSDictionary:retDic[@"b"]];
        if ([retDic[@"a"] intValue] == 1) {
            [UMSocialData defaultData].extConfig.qqData.url = Dic[@"connect"];
            [UMSocialData defaultData].extConfig.wechatSessionData.url = Dic[@"connect"];
            [UMSocialData defaultData].extConfig.sinaData.urlResource.url = Dic[@"connect"];
            [UMSocialSnsService presentSnsIconSheetView:self
                                                 appKey:UMKEY
                                              shareText:Dic[@"describe"]
                                             shareImage:[UIImage imageNamed:@"icon.png"]
                                        shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToQQ,UMShareToWechatSession,UMShareToWechatTimeline,nil]
                                               delegate:nil];
        }else if ([retDic[@"a"] intValue] == 0) {
            NSLog(@"00000000000");
            
        }else if([retDic[@"a"] intValue] == -1){
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        TJJALERT_VIEW(ERROR_NETWORKINFO);
    }];
}

#pragma mark -
#pragma mark 睡眠得分
- (IBAction)sleepIntegralClick {
    self.sleepScore.image= [UIImage imageNamed:@"integralleftScoreOn"];
    self.sleeptime.image = [UIImage imageNamed:@"integrallefTimeOff"];
    self.judgeScoreOrTime = NO;
    [self.SleepTableView reloadData];
}

#pragma mark -
#pragma mark 睡眠时间
- (IBAction)sleepTimeClick {
    self.sleepScore.image = [UIImage imageNamed:@"integralleftScoreOff"];
    self.sleeptime.image = [UIImage imageNamed:@"integralleftTimeOn"];
    self.judgeScoreOrTime = YES;
    [self.SleepTableView reloadData];
}

-(void)judgeBackGroundTime
{
    long long int currentTimeInt = [TJJDefines getTimeIntSince1970Current];
    if (currentTimeInt>=16200&& currentTimeInt <=34200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundOne"];
    }
    else if (currentTimeInt>34200 && currentTimeInt<=55800)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundTwo"];
    }
    else if (currentTimeInt>55800 && currentTimeInt<=70200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundThree"];
    }
    else if(currentTimeInt >70200 || currentTimeInt<16200)
    {
        self.backGround.image = [UIImage imageNamed:@"background_night"];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (alertView.tag) {
        case 97:
        {//重新登录
            UserConfig *config = [UserConfig sharingUserConfig];
            [config setHaveLogin:@"lalala"];
            [config setToken:@"123"];
            [config setUserHeadData:nil];
            UIStoryboard *LoginSt = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
            LoginViewController *loginVc = [LoginSt instantiateViewControllerWithIdentifier:@"loginViewId"];
            loginVc.quit = YES;
            [self.navigationController pushViewController:loginVc animated:YES];
        }
            break;
        default:
            break;
    }
}

@end
